import { $x } from 'party_fe_component'

export function loadOrgTags(tagTypes = [3, 4]) {
    var pars = {
        businessType: $x.tokenUtil.businessType,
        spId: $x.tokenUtil.spId,
        tagTypes
    }
    return $x.post('/org/tag/query', pars)
}

export function loadParentLabel(orgId, labelIdList) {
    var pars = {
        id: orgId,
        labelIdList,
        businessType: $x.tokenUtil.businessType,
        spId: $x.tokenUtil.spId
    };
    return $x.post('/org/org/v2/get-parent-by-label', pars);
}

// type: 组织字段模板  = ‘Org', 人员字段模板 = 'Member'
export function loadTemplates(isMember) {
    var pars = {
        params: {
            //formName: '',
            // name: '',`
            type: isMember ? 'Member' : 'Org',
        }
    }
    return $x.post('/form/model/qry', pars)
}

export function loadUIPage(formName, pageType, clientType) {
    var pars = {
        appId: $x.tokenUtil.appId,
        businessType: $x.tokenUtil.businessType,
        spId: $x.tokenUtil.spId,
    }
    return $x.get(`/form/model/${formName}/ui/${pageType}${clientType ? '/' + clientType : ''}`, pars)
}

export function modifyPage(tplId, pageId, data) {
    return $x.put(`form/model/page/ui/${tplId}/${pageId}`, data)
}

export function addPage(tplId, pageId, data) {
    return $x.post(`form/model/page/ui`, data)
}

export function modifyMeta(tplId, data) {
    return $x.put(`form/model/${tplId}/metadata`, data)
}

export function modifyTpl(tplId, data) {
    return $x.put(`form/model/${tplId}`, data)
}

export function getOrgConfig() {
    var pars = {
        appId: $x.tokenUtil.appId,
        businessType: $x.tokenUtil.businessType,
        spId: $x.tokenUtil.spId,
    }
    return $x.post('/orginfo/org/initconfig/query', pars)
}

export function getMemberConfig() {
    var pars = {
        appId: $x.tokenUtil.appId,
        businessType: $x.tokenUtil.businessType,
        spId: $x.tokenUtil.spId,
    }
    return $x.post('/userinfo/user/initconfig/query', pars)
}

export function orgBatchMove(ids, target) {
    const params = {
        idList: ids,
        target_group_id: target
    };

    return $x.post('/orginfo/orgOperation/orgBatchMove', params)
};

export function memberBatchMove(ids, origin, target) {
    const params = {
        originGroupId: origin,
        targetGroupId: target,
        userIdList: ids
    };

    return $x.post('/userinfo/movement/save', params)
}

export function queryMoveList(page, type, ids) {
    const params = {
        page,
        movementType: type
    };

    if (ids) {
        params.groupIds = ids;
    }

    return $x.post('/userinfo/movement/query', params);
}

export function queryMoveUserList(id) {
    return $x.get(`/userinfo/movement/${id}/userList`);
}

export function cancelUserMove(id) {
    return $x.post(`/userinfo/movement/${id}/cancelMove`);
}

export function tackleMove(id, dealType) {
    const params = {
        moveId: id,
        dealType
    };

    return $x.post(`/userinfo/movement/dealApply`, params);
}


// 获取当前场景配置
export function loadUIPageCur(formName) {
    return $x.get(`/userinfo/customizedFields/${formName}`)
}

// 保存当前场景配置
export function modifyPageCur(formName, data) {
    return $x.post(`/userinfo/customizedFields/${formName}`, data)
}
